package com;

import com.alibaba.fastjson.JSONObject;
import com.go2.shipping.common.encrypt.AES;
import com.yuhang.demo.util.PostUtil;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LoginTest {


    public static void main(String[] args) throws IOException {


        System.out.println(yy("00191*2", 1));
        System.out.println(yy("00191*2-0", 1));
        System.out.println(yy("00191*2-1", 1));


        System.out.println(yy("00191-1*3", 1));

        System.out.println(yy("00191-1*3-0", 1));
    }

    private static String yy(String takeCode, int newQuantity) {
        String[] tokenArr = takeCode.split("-");
        String takeNumber;
        int count = 1;
        if (tokenArr.length == 1) {
            //还未拆分过
            String[] zs = takeCode.split("\\*");
            if (zs.length == 1) {
                takeNumber = takeCode;
            } else {
                takeNumber = zs[0] + "*" + newQuantity + "-" + count;
            }
        } else if (tokenArr.length == 2) {
            //可能拆分过，也可能没有拆分
            String[] zs = tokenArr[0].split("\\*");
            if (zs.length == 2) {
                //拆分过
                takeNumber = zs[0] + "*" + newQuantity + "-" + count;
            } else {
                //未拆分过
                String[] os = tokenArr[1].split("\\*");
                takeNumber = tokenArr[0] + "-" + os[0] + "*" + newQuantity + "-" + count;
            }
        } else {
            String[] os = tokenArr[1].split("\\*");
            takeNumber = tokenArr[0] + "-" + os[0] + "*" + newQuantity + "-" + count;
        }

        return takeNumber;
    }



    private static String xx(String takeCode, int newQuantity) {
        String[] tokenArr = takeCode.split("-");
        String takeNumber;
        if (tokenArr.length == 1) {
            //还未拆分过
            String[] zs = takeCode.split("\\*");
            if (zs.length == 1) {
                takeNumber = takeCode;
            } else {
                takeNumber = zs[0] + "*" + newQuantity + "-"+"0";
            }
        } else if (tokenArr.length == 2) {
            //可能拆分过，也可能没有拆分
            String[] zs = tokenArr[0].split("\\*");
            if (zs.length == 2) {
                //拆分过
                takeNumber = zs[0] + "*" + newQuantity +"-"+ tokenArr[1];
            } else {
                //未拆分过
                String[] os = tokenArr[1].split("\\*");
                takeNumber = tokenArr[0] + "-" + os[0] + "*" + newQuantity + "-"+"0";
            }
        } else {
            String[] os = tokenArr[1].split("\\*");
            takeNumber = tokenArr[0] + "-" + os[0] + "*" + newQuantity + "-"+tokenArr[2];
        }
        
        return takeNumber;
    }
}
